package com.desmart.renjiao.employeeself;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.desmart.renjiao.R;
import com.desmart.renjiao.contants.Constants;
import com.desmart.renjiao.main.adapter.HomeItemType;
import com.desmart.renjiao.main.bean.EmptyLine;
import com.desmart.renjiao.main.bean.HomeIcons;
import com.desmart.renjiao.main.bean.Title;
import com.lemon.library.common.ARoutePath;
import com.lemon.library.common.CommonActivity;
import com.lemon.library.common.router.JumpUtils;
import com.lemon.library.utils.ToastUtils;

import java.util.ArrayList;
import java.util.List;

@Route(path = ARoutePath.workplace.EmployeeSelfServiceActivity)
public class EmployeeSelfServiceActivity extends CommonActivity<EmployeeSelfM,EmployeeSelfP> implements EmployeeSelf.EmployeeSelfV, EmployeeTypeAdapter.OnEmployeeItemClick {

    private RecyclerView recyclerView;
    private EmployeeTypeAdapter mAdapter;

    private static ArrayList<HomeIcons.Icon> list1 = new ArrayList<>();
    private static ArrayList<HomeIcons.Icon> list2 = new ArrayList<>();
    private static ArrayList<HomeIcons.Icon> list3 = new ArrayList<>();
    private static ArrayList<HomeIcons.Icon> list4 = new ArrayList<>();

    static {
        list1.add(new HomeIcons.Icon(R.string.xuelixiugaishengqing,R.drawable.icon_home_yuangongzizhu));
        list1.add(new HomeIcons.Icon(R.string.ziliaoxiugaishengqing,R.drawable.icon_home_yuangongzizhu));

        list2.add(new HomeIcons.Icon(R.string.gerengongzichaxun,R.drawable.icon_home_yuangongzizhu));

        list3.add(new HomeIcons.Icon(R.string.xiujiachuqinshenqing,R.drawable.icon_home_yuangongzizhu));
        list3.add(new HomeIcons.Icon(R.string.xiaojiashenqing,R.drawable.icon_home_yuangongzizhu));
        list3.add(new HomeIcons.Icon(R.string.gerenkaoqinchaxun,R.drawable.icon_home_yuangongzizhu));
        list3.add(new HomeIcons.Icon(R.string.yuedukaoqinguanli,R.drawable.icon_home_yuangongzizhu));

        list4.add(new HomeIcons.Icon(R.string.cankaxinxichaxun,R.drawable.icon_home_yuangongzizhu));
        list4.add(new HomeIcons.Icon(R.string.danfeichaxun,R.drawable.icon_home_yuangongzizhu));
        list4.add(new HomeIcons.Icon(R.string.danweidanfeichaxun,R.drawable.icon_home_yuangongzizhu));
        list4.add(new HomeIcons.Icon(R.string.qitayiliaobaozhangeduchaxun,R.drawable.icon_home_yuangongzizhu));
        list4.add(new HomeIcons.Icon(R.string.danweiqitayiliaobaozhangeduchaxun,R.drawable.icon_home_yuangongzizhu));

    }

    private String key;


    @Override
    public int bindLayout() {
        return R.layout.activity_employee_self_service;
    }

    @Override
    public void initView(Activity activity) {
        setTitleText(getString(R.string.yuangongzizhu));
        recyclerView = activity.findViewById(R.id.recyclerview);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new EmployeeTypeAdapter(getPlaceHolderData());
        recyclerView.setAdapter(mAdapter);

        mAdapter.setOnEmployeeItemClick(this);
    }

    @Override
    public void initData(Context context) {
    }

    public List<HomeItemType> getPlaceHolderData() {
        List<HomeItemType> list = new ArrayList<>();
        list.add(new Title(getString(R.string.employeeself_title1)));
        list.add(new HomeIcons(list1));
        list.add(new EmptyLine());
        list.add(new Title(getString(R.string.employeeself_title2)));
        list.add(new HomeIcons(list2));
        list.add(new EmptyLine());
        list.add(new Title(getString(R.string.employeeself_title3)));
        list.add(new HomeIcons(list3));
        list.add(new EmptyLine());
        list.add(new Title(getString(R.string.employeeself_title4)));
        list.add(new HomeIcons(list4));
        list.add(new EmptyLine());
        return list;
    }

    @Override
    public void onNetStart(String tag, String startMsg) {
        super.onNetStart(tag, startMsg);
        showLoading();
    }

    @Override
    public void onNetFinish(String tag, String startMsg) {
        super.onNetFinish(tag, startMsg);
        hideLoading();
    }

    @Override
    public void onSuccessGetKey(String key, int title) {
        this.key = key;
        switch (title){
            case R.string.xuelixiugaishengqing:
                JumpWebEmployee(Constants.employeeself_0,getString(R.string.xuelixiugaishengqing));
                break;
            case R.string.ziliaoxiugaishengqing:
                JumpWebEmployee(Constants.employeeself_1,getString(R.string.ziliaoxiugaishengqing));
                break;
            case R.string.gerengongzichaxun:
                JumpWebEmployee(Constants.employeeself_2,getString(R.string.gerengongzichaxun));
                break;
            case R.string.cankaxinxichaxun:
                JumpWebEmployee(Constants.employeeself_3,getString(R.string.cankaxinxichaxun));
                break;
            case R.string.danfeichaxun:
                JumpWebEmployee(Constants.employeeself_4,getString(R.string.danfeichaxun));
                break;
            case R.string.danweidanfeichaxun:
                JumpWebEmployee(Constants.employeeself_5,getString(R.string.danweidanfeichaxun));
                break;
            case R.string.qitayiliaobaozhangeduchaxun:
                JumpWebEmployee(Constants.employeeself_6,getString(R.string.qitayiliaobaozhangeduchaxun));
                break;
            case R.string.danweiqitayiliaobaozhangeduchaxun:
                JumpWebEmployee(Constants.employeeself_7,getString(R.string.danweiqitayiliaobaozhangeduchaxun));
                break;
            case R.string.xiujiachuqinshenqing:
                JumpWebEmployee(Constants.employeeself_8,getString(R.string.xiujiachuqinshenqing));
                break;
            case R.string.xiaojiashenqing:
                JumpWebEmployee(Constants.employeeself_9,getString(R.string.xiaojiashenqing));
                break;
            case R.string.gerenkaoqinchaxun:
                JumpWebEmployee(Constants.employeeself_10,getString(R.string.gerenkaoqinchaxun));
                break;
            case R.string.yuedukaoqinguanli:
                JumpWebEmployee(Constants.employeeself_11,getString(R.string.yuedukaoqinguanli));
                break;
            default:
                ToastUtils.showGravity("暂未开发");
                break;
        }
    }

    private void JumpWebEmployee(String Id,String name) {
        String url = Constants.EmployeeSelfUrl + Id + "&NavMode=1&CurrentWindowId=&TarTitle="
                + name + "&sso_ticket=" + key;
        JumpUtils.toWeb(this,url,name);
    }

    @Override
    public void onClickIcon(int title) {
        mPresenter.getEmployeesPort(title);
    }


}
